const router = require('koa-router')();
const areacodeModel = require("../models/areacode");
const areacode = areacodeModel();
const dictSummaryModel = require("../models/dict_summary");
const dictSummary = dictSummaryModel();

router.prefix('/hangao')

/**
 * 测试连接
 */
router.get('/areacode', async (ctx, next) => {
    let resStr;
    try {
       const resData = await areacode.findAll();
        resStr = '瀚高 Connection has been established successfully.';
        console.log(resData);
    } catch (error) {
        resStr = `Unable to connect to the database:${error}`;
        console.error(resStr);
    }
    ctx.body = `this is a hangao/list response:${resStr}`;
})

router.post('/dictSummary', async (ctx, next) => {
    let resStr;
    let resData = {};
    try {
       resData = await dictSummary.findAll();
        resStr = '瀚高  dictSummary 查询成功.';
        console.log(resData);
    } catch (error) {
        resStr = `Unable to connect to the database:${error}`;
        console.error(resStr);
    }
    ctx.body = resData;
})

module.exports = router